+2005-08-16 Øyvind Kolås <pippin@gimp.org>
+
+ * babl/babl-component.[ch]
+ * babl/babl-conversion.[ch]
+ * babl/babl-fish.[ch]
+ * babl/babl-image.[ch]
+ * babl/babl-instance.h
+ * babl/babl-internal.h
+ * babl/babl-introspect.c
+ * babl/babl-model.[ch]
+ * babl/babl-pixel-format.[ch]
+ * babl/babl-sampling.[ch]
+ * babl/babl-sanity.c
+ * babl/babl-type.[ch]
+ * tests/float_to_u8.c
+ * tests/grayscale_to_rgb.c
+ * tests/rgb_to_lab_to_rgb.c
+ * tests/rgb_to_ycbcr.c
+ * tests/rgb_to_ycbcr_to_rgb.c
+ * tests/u8_to_float.c: Changed to use polymorph Babl * union's instead
+ of class specific structs in most cases, and in all cases for the
+ public API.
+
2005-08-16 Øyvind Kolås <pippin@gimp.org>
* AUTHORS: Fixed spelling of Sven Neumann.
return 0; /* continue iterating */
}
-static BablComponent *
+static Babl *
component_new (const char *name,
int id,
int luma,
int chroma,
int alpha)
{
- Babl *self;
+ Babl *babl;
- self = babl_calloc (sizeof (BablComponent), 1);
- self->class_type = BABL_COMPONENT;
- self->instance.id = id;
- self->instance.name = babl_strdup (name);
- self->component.luma = luma;
- self->component.chroma = chroma;
- self->component.alpha = alpha;
+ babl = babl_calloc (sizeof (BablComponent), 1);
+ babl->class_type = BABL_COMPONENT;
+ babl->instance.id = id;
+ babl->instance.name = babl_strdup (name);
+ babl->component.luma = luma;
+ babl->component.chroma = chroma;
+ babl->component.alpha = alpha;
- return (BablComponent*) self;
+ return babl;
}
-BablComponent *
+Babl *
babl_component_new (const char *name,
...)
{
va_list varg;
- BablComponent *self;
- int id = 0;
- int luma = 0;
- int chroma = 0;
- int alpha = 0;
- const char *arg=name;
+ Babl *babl;
+ int id = 0;
+ int luma = 0;
+ int chroma = 0;
+ int alpha = 0;
+ const char *arg=name;
va_start (varg, name);
va_end (varg);
- self = component_new (name, id, luma, chroma, alpha);
+ babl = component_new (name, id, luma, chroma, alpha);
- if ((BablComponent*) db_insert ((Babl*)self) == self)
+ if (db_insert (babl) == babl)
{
- return self;
+ return babl;
}
else
{
- each_babl_component_destroy ((Babl*)self, NULL);
+ each_babl_component_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE(BablComponent, babl_component, "BablComponent")
+BABL_CLASS_TEMPLATE (babl_component)
#define _BABL_COMPONENT_H
#include "babl-classes.h"
-BABL_DEFINE_CLASS(BablComponent, babl_component)
+BABL_DEFINE_CLASS (babl_component)
#endif
return 0; /* continue iterating */
}
-static BablConversion *
+static Babl *
conversion_new (const char *name,
int id,
Babl *source,
BablFuncPlanar planar,
BablFuncPlanarBit planar_bit)
{
- Babl *self = NULL;
+ Babl *babl = NULL;
/* destination is of same type as source */
switch (source->class_type)
case BABL_TYPE:
if (linear)
{
- self = babl_calloc (sizeof (BablConversionType), 1);
- self->class_type = BABL_CONVERSION_TYPE;
- self->conversion.function.linear = linear;
+ babl = babl_calloc (sizeof (BablConversionType), 1);
+ babl->class_type = BABL_CONVERSION_TYPE;
+ babl->conversion.function.linear = linear;
}
else if (planar)
{
- self = babl_calloc (sizeof (BablConversionTypePlanar), 1);
- self->class_type = BABL_CONVERSION_TYPE_PLANAR;
- self->conversion.function.planar = planar;
+ babl = babl_calloc (sizeof (BablConversionTypePlanar), 1);
+ babl->class_type = BABL_CONVERSION_TYPE_PLANAR;
+ babl->conversion.function.planar = planar;
}
else if (planar_bit)
{
}
else if (planar)
{
- self = babl_calloc (sizeof (BablConversionModelPlanar), 1);
- self->class_type = BABL_CONVERSION_MODEL_PLANAR;
- self->conversion.function.planar = planar;
+ babl = babl_calloc (sizeof (BablConversionModelPlanar), 1);
+ babl->class_type = BABL_CONVERSION_MODEL_PLANAR;
+ babl->conversion.function.planar = planar;
}
else if (planar_bit)
{
case BABL_PIXEL_FORMAT:
if (linear)
{
- self = babl_calloc (sizeof (BablConversionPixelFormat), 1);
- self->class_type = BABL_CONVERSION_PIXEL_FORMAT;
- self->conversion.function.linear = linear;
+ babl = babl_calloc (sizeof (BablConversionPixelFormat), 1);
+ babl->class_type = BABL_CONVERSION_PIXEL_FORMAT;
+ babl->conversion.function.linear = linear;
}
else if (planar)
{
- self = babl_calloc (sizeof (BablConversionPixelFormatPlanar), 1);
- self->class_type = BABL_CONVERSION_PIXEL_FORMAT_PLANAR;
- self->conversion.function.planar = planar;
+ babl = babl_calloc (sizeof (BablConversionPixelFormatPlanar), 1);
+ babl->class_type = BABL_CONVERSION_PIXEL_FORMAT_PLANAR;
+ babl->conversion.function.planar = planar;
}
else if (planar_bit)
{
default:
break;
}
- if (!self)
+ if (!babl)
{
babl_log ("%s(name='%s', ...): creation failed", __FUNCTION__, name);
return NULL;
}
- self->instance.id = id;
- self->instance.name = babl_strdup (name);
- self->conversion.source = (union Babl*)source;
- self->conversion.destination = (union Babl*)destination;
- self->conversion.time_cost = time_cost;
- self->conversion.loss = loss;
+ babl->instance.id = id;
+ babl->instance.name = babl_strdup (name);
+ babl->conversion.source = (union Babl*)source;
+ babl->conversion.destination = (union Babl*)destination;
+ babl->conversion.time_cost = time_cost;
+ babl->conversion.loss = loss;
- babl_add_ptr_to_list ((void ***)&(source->type.from), self);
- babl_add_ptr_to_list ((void ***)&(destination->type.to), self);
+ babl_add_ptr_to_list ((void ***)&(source->type.from), babl);
+ babl_add_ptr_to_list ((void ***)&(destination->type.to), babl);
- return (BablConversion*)self;
+ return babl;
}
-BablConversion *
+Babl *
babl_conversion_new (const char *name,
...)
{
va_list varg;
- BablConversion *self;
+ Babl *babl;
int id = 0;
Babl *source = NULL;
assert (source);
assert (destination);
- self = conversion_new (name, id,
- source, destination, time_cost, loss, linear, planar, planar_bit);
+ babl = conversion_new (name, id, source, destination, time_cost, loss, linear,
+ planar, planar_bit);
- if ((BablConversion*) db_insert ( (Babl*)self) == self)
+ if (db_insert (babl) == babl)
{
- return self;
+ return babl;
}
else
{
- each_babl_conversion_destroy ( (Babl*)self, NULL);
+ each_babl_conversion_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE(BablConversion, babl_conversion, "BablConversion")
+BABL_CLASS_TEMPLATE (babl_conversion)
#include "babl-classes.h"
-BABL_DEFINE_CLASS(BablConversion, babl_conversion)
+BABL_DEFINE_CLASS (babl_conversion)
#endif
{
SearchData *sd = user_data;
- if ((Babl*)babl->conversion.source == sd->source &&
- (Babl*)babl->conversion.destination == sd->destination)
+ if (BABL(babl->conversion.source) == sd->source &&
+ BABL(babl->conversion.destination) == sd->destination)
{
sd->result = (BablConversion*)babl;
return 1;
return 0;
}
-BablConversion *babl_conversion_find (Babl *source,
- Babl *destination)
+BablConversion *babl_conversion_find (void *source,
+ void *destination)
{
SearchData data;
- data.source = source;
- data.destination = destination;
+ data.source = BABL(source);
+ data.destination = BABL(destination);
data.result = NULL;
babl_conversion_each (find_conversion, &data);
if (!data.result)
{
babl_log ("%s('%s', '%s'): failed, aborting", __FUNCTION__,
- source->instance.name, destination->instance.name);
+ data.source->instance.name, data.destination->instance.name);
exit (-1);
return NULL;
}
return data.result;
}
-BablFish *
+Babl *
babl_fish_reference_new (Babl *source,
Babl *destination)
{
babl->reference_fish.type_to_double =
babl_conversion_find (
- (Babl*)source->pixel_format.type[0],
- (Babl*)babl_type_id (BABL_DOUBLE)
+ source->pixel_format.type[0],
+ babl_type_id (BABL_DOUBLE)
);
babl->reference_fish.model_to_rgba =
babl_conversion_find (
- (Babl*)source->pixel_format.model[0],
- (Babl*)babl_model_id (BABL_RGBA)
+ source->pixel_format.model[0],
+ babl_model_id (BABL_RGBA)
);
babl->reference_fish.rgba_to_model =
babl_conversion_find (
- (Babl*)babl_model_id (BABL_RGBA),
- (Babl*)destination->pixel_format.model[0]
+ babl_model_id (BABL_RGBA),
+ destination->pixel_format.model[0]
);
babl->reference_fish.double_to_type =
babl_conversion_find (
- (Babl*)babl_type_id (BABL_DOUBLE),
- (Babl*)destination->pixel_format.type[0]
+ babl_type_id (BABL_DOUBLE),
+ destination->pixel_format.type[0]
);
if (db_insert (babl) == babl)
{
- return (BablFish*)babl;
+ return babl;
}
else
{
babl_add_ptr_to_list ((void ***)&(source->type.from), babl);
babl_add_ptr_to_list ((void ***)&(destination->type.to), babl);
*/
- return (BablFish*) babl;
+ return babl;
}
-BablFish *
+Babl *
babl_fish (Babl *source,
Babl *destination)
{
int n)
{
Babl *babl;
- BablImage *imageA;
- BablImage *imageB;
- BablImage *imageC;
+ Babl *imageA;
+ Babl *imageB;
+ Babl *imageC;
fooA = babl_malloc(sizeof (double) * n * 4);
fooB = babl_malloc(sizeof (double) * n * 4);
/* calculate planar representation of fooA, and fooB */
- imageA = babl_image_new_from_linear (fooA,
- (Babl*) ((BablPixelFormat*) babl->fish.source)->model[0]);
- imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA));
+ imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> pixel_format.model[0]));
+ imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA));
/* transform fooA into fooB fooB is rgba double */
((BablConversion*)(babl->reference_fish.model_to_rgba))->function.planar(
- imageA->bands,
- imageA->data,
- imageA->pitch,
- imageB->bands,
- imageB->data,
- imageB->pitch,
+ imageA->image.bands,
+ imageA->image.data,
+ imageA->image.pitch,
+ imageB->image.bands,
+ imageB->image.data,
+ imageB->image.pitch,
n);
babl_free (imageA);
babl_free (imageB);
/* calculate planar representation of fooC */
/* transform fooB into fooC fooC is ???? double */
- imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA));
- imageC = babl_image_new_from_linear (fooA, (Babl*)((BablPixelFormat*)babl->fish.destination)->model[0]);
+ imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA));
+ imageC = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.destination))->pixel_format.model[0]));
((BablConversion*)(babl->reference_fish.rgba_to_model))->function.planar(
- imageB->bands,
- imageB->data,
- imageB->pitch,
- imageC->bands,
- imageC->data,
- imageC->pitch,
+ imageB->image.bands,
+ imageB->image.data,
+ imageB->image.pitch,
+ imageC->image.bands,
+ imageC->image.data,
+ imageC->image.pitch,
n);
#include "babl-classes.h"
-BABL_DEFINE_CLASS_NO_NEW_NO_ID(BablFish, babl_fish)
+BABL_DEFINE_CLASS_NO_NEW_NO_ID(babl_fish)
-BablFish *
-babl_fish_new (Babl *source,
- Babl *destination);
-
-BablFish *
+Babl *
babl_fish (Babl *source,
Babl *destination);
* allowed as well as BablImage objects in their place
*/
int
-babl_fish_process (BablFish *babl_fish,
- void *source,
- void *destination,
- int n);
+babl_fish_process (Babl *babl_fish,
+ void *source,
+ void *destination,
+ int n);
/* whether the BablFish needs a BablImage to do the processing,
* or void * are sufficient.
*/
int
-babl_fish_needs_image (BablFish *babl_dish);
+babl_fish_needs_image (Babl *babl_fish);
#endif
return 0; /* continue iterating */
}
-static BablPixelFormat *
+static Babl *
pixel_format_new (const char *name,
int id,
int planar,
BablSampling **sampling,
BablType **type)
{
- Babl *self;
+ Babl *babl;
int band;
- self = babl_calloc (sizeof (BablPixelFormat), 1);
+ babl = babl_calloc (sizeof (BablPixelFormat), 1);
- self->class_type = BABL_PIXEL_FORMAT;
- self->instance.id = id;
- self->instance.name = babl_strdup (name);
+ babl->class_type = BABL_PIXEL_FORMAT;
+ babl->instance.id = id;
+ babl->instance.name = babl_strdup (name);
- self->pixel_format.bands = bands;
- self->pixel_format.planar = planar;
+ babl->pixel_format.bands = bands;
+ babl->pixel_format.planar = planar;
- self->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1));
- self->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1));
- self->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1));
- self->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1));
+ babl->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1));
+ babl->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1));
+ babl->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1));
+ babl->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1));
for (band=0; band < bands; band++)
{
- self->pixel_format.model[band] = model[band];
- self->pixel_format.component[band] = component[band];
- self->pixel_format.type[band] = type[band];
- self->pixel_format.sampling[band] = sampling[band];
+ babl->pixel_format.model[band] = model[band];
+ babl->pixel_format.component[band] = component[band];
+ babl->pixel_format.type[band] = type[band];
+ babl->pixel_format.sampling[band] = sampling[band];
}
- self->pixel_format.model[band] = NULL;
- self->pixel_format.component[band] = NULL;
- self->pixel_format.type[band] = NULL;
- self->pixel_format.sampling[band] = NULL;
+ babl->pixel_format.model[band] = NULL;
+ babl->pixel_format.component[band] = NULL;
+ babl->pixel_format.type[band] = NULL;
+ babl->pixel_format.sampling[band] = NULL;
- return (BablPixelFormat*)self;
+ return babl;
}
-BablPixelFormat *
+Babl *
babl_pixel_format_new (const char *name,
...)
{
va_list varg;
- BablPixelFormat *self;
+ Babl *babl;
int id = 0;
int planar = 0;
int bands = 0;
BablSampling *sampling [BABL_MAX_BANDS];
BablType *type [BABL_MAX_BANDS];
- BablSampling *current_sampling = babl_sampling (1,1);
- BablType *current_type = babl_type_id (BABL_U8);
+ BablSampling *current_sampling = (BablSampling*) babl_sampling (1,1);
+ BablType *current_type = (BablType*) babl_type_id (BABL_U8);
BablModel *current_model = NULL;
const char *arg = name;
va_end (varg);
- self = pixel_format_new (name, id,
+ babl = pixel_format_new (name, id,
planar,
bands,
model, component, sampling, type);
- if ((BablPixelFormat*) db_insert ((Babl*)self) == self)
+ if (db_insert (babl) == babl)
{
- return self;
+ return babl;
}
else
{
- each_babl_pixel_format_destroy ((Babl*)self, NULL);
+ each_babl_pixel_format_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE (BablPixelFormat, babl_pixel_format, "BablPixelFormat")
+BABL_CLASS_TEMPLATE (babl_pixel_format)
#define _BABL_PIXEL_FORMAT_H
#include "babl-classes.h"
-BABL_DEFINE_CLASS(BablPixelFormat, babl_pixel_format)
+BABL_DEFINE_CLASS (babl_pixel_format)
#endif
}
#endif
-static BablImage *
+static Babl *
image_new (int bands,
BablComponent **component,
void **data,
int *pitch,
int *stride)
{
- Babl *self;
+ Babl *babl;
int band;
- self = babl_calloc (
+ babl = babl_calloc (
sizeof (BablImage) +
sizeof (BablComponent*) * (bands+1) +
sizeof (void*) * (bands+1) +
sizeof (int) * (bands+1) +
sizeof (int) * (bands+1),1);
- self->image.component = ((void *)self) + sizeof (BablImage);
- self->image.data = ((void *)self->image.component) + sizeof (BablComponent*) * (bands+1);
- self->image.pitch = ((void *)self->image.data) + sizeof (void*) * (bands+1);
- self->image.stride = ((void *)self->image.pitch) + sizeof (int) * (bands+1);
-/*self->image.foo = ((void *)self->image.stride) + sizeof (int) * (bands+1);*/
+ babl->image.component = ((void *)babl) + sizeof (BablImage);
+ babl->image.data = ((void *)babl->image.component) + sizeof (BablComponent*) * (bands+1);
+ babl->image.pitch = ((void *)babl->image.data) + sizeof (void*) * (bands+1);
+ babl->image.stride = ((void *)babl->image.pitch) + sizeof (int) * (bands+1);
+/*babl->image.foo = ((void *)babl->image.stride) + sizeof (int) * (bands+1);*/
- self->class_type = BABL_IMAGE;
- self->instance.id = 0;
- self->instance.name = "babl image";
+ babl->class_type = BABL_IMAGE;
+ babl->instance.id = 0;
+ babl->instance.name = "babl image";
- self->image.bands = bands;
+ babl->image.bands = bands;
for (band=0; band < bands; band++)
{
- self->image.component[band] = component[band];
- self->image.data[band] = data[band];
- self->image.pitch[band] = pitch[band];
- self->image.stride[band] = stride[band];
+ babl->image.component[band] = component[band];
+ babl->image.data[band] = data[band];
+ babl->image.pitch[band] = pitch[band];
+ babl->image.stride[band] = stride[band];
}
- self->image.component[band] = NULL;
- self->image.data[band] = NULL;
- self->image.pitch[band] = 0;
- self->image.stride[band] = 0;
+ babl->image.component[band] = NULL;
+ babl->image.data[band] = NULL;
+ babl->image.pitch[band] = 0;
+ babl->image.stride[band] = 0;
- return (BablImage*) self;
+ return babl;
}
-BablImage *
+Babl *
babl_image_new_from_linear (void *buffer,
- Babl *babl)
+ Babl *format)
{
- BablImage *self;
+ Babl *babl;
int band;
BablComponent *component [BABL_MAX_BANDS];
void *data [BABL_MAX_BANDS];
int offset=0;
int calc_pitch=0;
- switch (babl->class_type)
+ switch (format->class_type)
{
case BABL_PIXEL_FORMAT:
- for (band=0; band < babl->pixel_format.bands; band++)
+ for (band=0; band < format->pixel_format.bands; band++)
{
- BablType *type = babl->pixel_format.type[band];
+ BablType *type = format->pixel_format.type[band];
calc_pitch += (type->bits / 8);
}
- for (band=0; band < babl->pixel_format.bands; band++)
+ for (band=0; band < format->pixel_format.bands; band++)
{
- BablType *type = babl->pixel_format.type[band];
+ BablType *type = format->pixel_format.type[band];
- component[band] = babl->pixel_format.component[band];
+ component[band] = format->pixel_format.component[band];
data[band] = buffer + offset;
pitch[band] = calc_pitch;
stride[band] = 0;
}
break;
case BABL_MODEL:
- for (band=0; band < babl->model.components; band++)
+ for (band=0; band < format->model.components; band++)
{
calc_pitch += (64 / 8);
}
- for (band=0; band < babl->model.components; band++)
+ for (band=0; band < format->model.components; band++)
{
- component[band] = babl->model.component[band];
+ component[band] = format->model.component[band];
data[band] = buffer + offset;
pitch[band] = calc_pitch;
stride[band] = 0;
break;
}
- self = image_new (babl->model.components, component, data, pitch, stride);
- return self;
+ babl = image_new (format->model.components, component, data, pitch, stride);
+ return babl;
}
-BablImage *
+Babl *
babl_image_new (void *first,
...)
{
va_list varg;
- BablImage *self;
+ Babl *babl;
int bands = 0;
BablComponent *component [BABL_MAX_BANDS];
void *data [BABL_MAX_BANDS];
}
else
{
- new_component = babl_component (arg);
+ new_component = (BablComponent*)babl_component (arg);
}
component [bands] = new_component;
va_end (varg);
- self = image_new (bands, component, data, pitch, stride);
+ babl = image_new (bands, component, data, pitch, stride);
- return self;
+ return babl;
}
void
#include "babl-classes.h"
-void babl_image_init (void);
-void babl_image_introspect (void);
-void babl_image_each (BablEachFunction each_fun,
- void *user_data);
-void babl_image_destroy (void);
-BablImage * babl_image_new (void *first_component,
+void babl_image_init (void);
+void babl_image_introspect (void);
+void babl_image_each (BablEachFunction each_fun,
+ void *user_data);
+void babl_image_destroy (void);
+Babl * babl_image_new (void *first_component,
...);
-/* create a new BablImage based on a packed BablPixelFormat (or BablModel assumed to
- * use only doubles).
+/* create a new BablImage based on a packed BablPixelFormat (or BablModel which
+ * is a virtual pixelformat based on the BablModel using only doubles in the
+ * order they are listed in the model.
*/
-BablImage *
+Babl *
babl_image_new_from_linear (void *buffer,
Babl *format);
#endif
* headers to a minimum, only the ones overriding the basic api with
* custom ways of construction.
*/
-#define BABL_DEFINE_CLASS(TypeName, type_name) \
+#define BABL_DEFINE_CLASS(type_name) \
\
-void type_name##_init (void); \
-void type_name##_destroy (void); \
-void type_name##_each (BablEachFunction each_fun, \
- void *user_data); \
-TypeName * type_name (const char *name); \
-TypeName * type_name##_id (int id); \
-TypeName * type_name##_new (const char *name, \
- ...);
-#define BABL_DEFINE_CLASS_NO_NEW_NO_ID(TypeName, type_name) \
+void type_name##_init (void); \
+void type_name##_destroy (void); \
+void type_name##_each (BablEachFunction each_fun, \
+ void *user_data); \
+Babl * type_name (const char *name); \
+Babl * type_name##_id (int id); \
+Babl * type_name##_new (const char *name, \
+ ...);
+#define BABL_DEFINE_CLASS_NO_NEW_NO_ID(type_name) \
\
-void type_name##_init (void); \
-void type_name##_destroy (void); \
-void type_name##_each (BablEachFunction each_fun, \
- void *user_data);
+void type_name##_init (void); \
+void type_name##_destroy (void); \
+void type_name##_each (BablEachFunction each_fun, \
+ void *user_data);
#endif
db_each (each_fun, user_data); \
} \
-#define BABL_DEFINE_LOOKUP_BY_ID(TypeName, type_name) \
-TypeName * \
+#define BABL_DEFINE_LOOKUP_BY_ID(type_name) \
+Babl * \
type_name##_id (int id) \
{ \
- return (TypeName*) db_exist (id, NULL); \
+ return db_exist (id, NULL); \
}
-#define BABL_DEFINE_LOOKUP_BY_NAME(TypeName, type_name) \
-TypeName * \
+#define BABL_DEFINE_LOOKUP_BY_NAME(type_name) \
+Babl * \
type_name (const char *name) \
{ \
- TypeName *ret; \
+ Babl *babl; \
\
if (babl_hmpf_on_name_lookups) \
{ \
babl_log ("%s(\"%s\"): hmpf!", __FUNCTION__, name); \
} \
- ret = (TypeName*) db_exist (0, name); \
+ babl = db_exist (0, name); \
\
- if (!ret) \
+ if (!babl) \
{ \
babl_log ("%s(\"%s\"): not found", __FUNCTION__, name); \
} \
- return ret; \
+ return babl; \
}
#define BABL_DEFINE_INIT(type_name) \
db_destroy (); \
}
-#define BABL_CLASS_TEMPLATE(TypeName, type_name, type_string) \
+#define BABL_CLASS_TEMPLATE(type_name) \
BABL_DEFINE_INIT (type_name) \
BABL_DEFINE_DESTROY (type_name) \
-BABL_DEFINE_LOOKUP_BY_NAME (TypeName, type_name) \
+BABL_DEFINE_LOOKUP_BY_NAME (type_name) \
BABL_DEFINE_EACH (type_name) \
-BABL_DEFINE_LOOKUP_BY_ID (TypeName, type_name)
+BABL_DEFINE_LOOKUP_BY_ID (type_name)
+#define BABL(obj) ((Babl*)(obj))
#endif
for (i=0; i< babl->model.components; i++)
{
babl_log ("\t\tindex[%i] = '%s'",
- i, ((Babl*)babl->model.component[i])->instance.name );
+ i, BABL(babl->model.component[i])->instance.name );
}
}
for (i=0; i< babl->pixel_format.bands; i++)
{
babl_log ("\t\tband[%i] type='%s' component='%s'",
- i, ( (Babl*)(babl->pixel_format.type[i] ))->instance.name,
- ( (Babl*)(babl->pixel_format.component[i]))->instance.name);
+ i, ( BABL(babl->pixel_format.type[i] ))->instance.name,
+ ( BABL(babl->pixel_format.component[i]))->instance.name);
}
}
#define BABL_MAX_COMPONENTS 32
-static BablModel *
+static Babl *
model_new (const char *name,
int id,
int components,
BablComponent **component)
{
- Babl *self;
+ Babl *babl;
int i;
- self = babl_calloc (sizeof (BablModel), 1);
+ babl = babl_calloc (sizeof (BablModel), 1);
- self->class_type = BABL_MODEL;
- self->instance.id = id;
- self->instance.name = babl_strdup (name);
- self->model.components = components;
- self->model.component = babl_malloc (sizeof (BablComponent*) * (components+1));
+ babl->class_type = BABL_MODEL;
+ babl->instance.id = id;
+ babl->instance.name = babl_strdup (name);
+ babl->model.components = components;
+ babl->model.component = babl_malloc (sizeof (BablComponent*) * (components+1));
for (i=0; i < components; i++)
{
- self->model.component[i] = component[i];
+ babl->model.component[i] = component[i];
}
- self->model.component[i] = NULL;
+ babl->model.component[i] = NULL;
- return (BablModel*)self;
+ return babl;
}
-BablModel *
+Babl *
babl_model_new (const char *name,
...)
{
- va_list varg;
- BablModel *self;
- int id = 0;
- int components = 0;
- BablComponent *band_component [BABL_MAX_COMPONENTS];
- const char *arg=name;
+ va_list varg;
+ Babl *babl;
+ int id = 0;
+ int components = 0;
+ BablComponent *band_component [BABL_MAX_COMPONENTS];
+ const char *arg=name;
va_start (varg, name);
va_end (varg);
- self = model_new (name, id, components, band_component);
+ babl = model_new (name, id, components, band_component);
- if ((BablModel*) db_insert ((Babl*)self) == self)
+ if (db_insert (babl) == babl)
{
- return self;
+ return babl;
}
else
{
- each_babl_model_destroy ((Babl*)self, NULL);
+ each_babl_model_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE (BablModel, babl_model, "BablModel")
+BABL_CLASS_TEMPLATE (babl_model)
#define _BABL_pixel_format_H
#include "babl-classes.h"
-BABL_DEFINE_CLASS(BablModel, babl_model)
+BABL_DEFINE_CLASS (babl_model)
#endif
return 0; /* continue iterating */
}
-static BablPixelFormat *
+static Babl *
pixel_format_new (const char *name,
int id,
int planar,
BablSampling **sampling,
BablType **type)
{
- Babl *self;
+ Babl *babl;
int band;
- self = babl_calloc (sizeof (BablPixelFormat), 1);
+ babl = babl_calloc (sizeof (BablPixelFormat), 1);
- self->class_type = BABL_PIXEL_FORMAT;
- self->instance.id = id;
- self->instance.name = babl_strdup (name);
+ babl->class_type = BABL_PIXEL_FORMAT;
+ babl->instance.id = id;
+ babl->instance.name = babl_strdup (name);
- self->pixel_format.bands = bands;
- self->pixel_format.planar = planar;
+ babl->pixel_format.bands = bands;
+ babl->pixel_format.planar = planar;
- self->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1));
- self->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1));
- self->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1));
- self->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1));
+ babl->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1));
+ babl->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1));
+ babl->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1));
+ babl->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1));
for (band=0; band < bands; band++)
{
- self->pixel_format.model[band] = model[band];
- self->pixel_format.component[band] = component[band];
- self->pixel_format.type[band] = type[band];
- self->pixel_format.sampling[band] = sampling[band];
+ babl->pixel_format.model[band] = model[band];
+ babl->pixel_format.component[band] = component[band];
+ babl->pixel_format.type[band] = type[band];
+ babl->pixel_format.sampling[band] = sampling[band];
}
- self->pixel_format.model[band] = NULL;
- self->pixel_format.component[band] = NULL;
- self->pixel_format.type[band] = NULL;
- self->pixel_format.sampling[band] = NULL;
+ babl->pixel_format.model[band] = NULL;
+ babl->pixel_format.component[band] = NULL;
+ babl->pixel_format.type[band] = NULL;
+ babl->pixel_format.sampling[band] = NULL;
- return (BablPixelFormat*)self;
+ return babl;
}
-BablPixelFormat *
+Babl *
babl_pixel_format_new (const char *name,
...)
{
va_list varg;
- BablPixelFormat *self;
+ Babl *babl;
int id = 0;
int planar = 0;
int bands = 0;
BablSampling *sampling [BABL_MAX_BANDS];
BablType *type [BABL_MAX_BANDS];
- BablSampling *current_sampling = babl_sampling (1,1);
- BablType *current_type = babl_type_id (BABL_U8);
+ BablSampling *current_sampling = (BablSampling*) babl_sampling (1,1);
+ BablType *current_type = (BablType*) babl_type_id (BABL_U8);
BablModel *current_model = NULL;
const char *arg = name;
va_end (varg);
- self = pixel_format_new (name, id,
+ babl = pixel_format_new (name, id,
planar,
bands,
model, component, sampling, type);
- if ((BablPixelFormat*) db_insert ((Babl*)self) == self)
+ if (db_insert (babl) == babl)
{
- return self;
+ return babl;
}
else
{
- each_babl_pixel_format_destroy ((Babl*)self, NULL);
+ each_babl_pixel_format_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE (BablPixelFormat, babl_pixel_format, "BablPixelFormat")
+BABL_CLASS_TEMPLATE (babl_pixel_format)
#define _BABL_PIXEL_FORMAT_H
#include "babl-classes.h"
-BABL_DEFINE_CLASS(BablPixelFormat, babl_pixel_format)
+BABL_DEFINE_CLASS (babl_pixel_format)
#endif
for (vertical=VERTICAL_MIN; vertical<=VERTICAL_MAX; vertical++)
{
int index= (vertical-VERTICAL_MIN) * VERTICAL_MAX + (horizontal - HORIZONTAL_MIN);
- if (each_fun ((Babl*) &(db[index]), user_data))
+ if (each_fun (BABL (&db[index]), user_data))
return;
}
}
#include "babl-classes.h"
-BABL_DEFINE_CLASS_NO_NEW_NO_ID(BablSampling, babl_sampling)
-BablSampling * babl_sampling (int horizontal,
- int vertical);
+BABL_DEFINE_CLASS_NO_NEW_NO_ID(babl_sampling)
+Babl * babl_sampling (int horizontal,
+ int vertical);
#endif
while (ptr && NULL!=*ptr)
{
- if (babl_conversion_destination ((Babl *)(*ptr)) == (Babl*)babl_type_id (BABL_DOUBLE))
+ if (babl_conversion_destination ((Babl *)(*ptr)) == babl_type_id (BABL_DOUBLE))
{
ok = 1;
break;
while (ptr && NULL!=*ptr)
{
- if (babl_conversion_source ((Babl *)(*ptr)) == (Babl*)babl_type_id (BABL_DOUBLE))
+ if (babl_conversion_source ((Babl *)(*ptr)) == babl_type_id (BABL_DOUBLE))
{
ok = 1;
break;
while (ptr && NULL!=*ptr)
{
- if (babl_conversion_destination ((Babl *)(*ptr)) == (Babl*)babl_model_id (BABL_RGBA))
+ if (babl_conversion_destination ((Babl *)(*ptr)) == babl_model_id (BABL_RGBA))
{
ok = 1;
break;
while (ptr && NULL!=*ptr)
{
- if (babl_conversion_source ((Babl *)(*ptr)) == (Babl*)babl_model_id (BABL_RGBA))
+ if (babl_conversion_source ((Babl *)(*ptr)) == babl_model_id (BABL_RGBA))
{
ok = 1;
break;
}
-static BablType *
+static Babl *
type_new (const char *name,
int id,
int bits)
{
- Babl *self;
+ Babl *babl;
assert (bits != 0);
assert (bits % 8 == 0);
- self = babl_calloc (sizeof (BablType), 1);
- self->class_type = BABL_TYPE;
- self->instance.id = id;
- self->instance.name = babl_strdup (name);
- self->type.bits = bits;
+ babl = babl_calloc (sizeof (BablType), 1);
+ babl->class_type = BABL_TYPE;
+ babl->instance.id = id;
+ babl->instance.name = babl_strdup (name);
+ babl->type.bits = bits;
- return (BablType*)self;
+ return babl;
}
-BablType *
+Babl *
babl_type_new (const char *name,
...)
{
- va_list varg;
- BablType *self;
- int id = 0;
- int bits = 0;
+ va_list varg;
+ Babl *babl;
+ int id = 0;
+ int bits = 0;
const char *arg=name;
va_end (varg);
- self = type_new (name, id, bits);
+ babl = type_new (name, id, bits);
- if ((BablType*) db_insert ((Babl*)self) == self)
+ if (db_insert (babl) == babl)
{
- return self;
+ return babl;
}
else
{
- each_babl_type_destroy ((Babl*)self, NULL);
+ each_babl_type_destroy (babl, NULL);
return NULL;
}
}
-BABL_CLASS_TEMPLATE (BablType, babl_type, "BablType")
+BABL_CLASS_TEMPLATE (babl_type)
#define _BABL_TYPE_H
#include "babl-classes.h"
-BABL_DEFINE_CLASS(BablType, babl_type)
+BABL_DEFINE_CLASS (babl_type)
#endif
int
test_float_to_rgb_u8 (void)
{
- BablFish *fish;
- int i;
- int OK=1;
+ Babl *fish;
+ int i;
+ int OK=1;
fish = babl_fish (
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"foo",
babl_model ("grayscale"),
babl_type ("float"),
babl_component ("luminance"),
NULL
),
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"bar",
babl_model ("grayscale"),
babl_type ("u8"),
int
test (void)
{
- BablFish *fish;
- int i;
- int OK=1;
+ Babl *fish;
+ int i;
+ int OK=1;
fish = babl_fish (
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"foo",
babl_model ("grayscale"),
babl_type ("float"),
babl_component ("luminance"),
NULL
),
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"bar",
babl_model ("rgb"),
babl_type ("float"),
int
test (void)
{
- BablFish *fish;
- int i;
- int OK=1;
+ Babl *fish;
+ int i;
+ int OK=1;
fish = babl_fish (
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"foo",
babl_model ("rgb"),
babl_type ("float"),
babl_component ("blue"),
NULL
),
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"bar",
babl_model ("CIE Lab"),
babl_type ("float"),
babl_fish_process (fish, source_buf, temp_buf, PIXELS);
- fish = babl_fish ((Babl*) babl_pixel_format ("bar"),
- (Babl*) babl_pixel_format ("foo"));
+ fish = babl_fish (babl_pixel_format ("bar"),
+ babl_pixel_format ("foo"));
babl_fish_process (fish, temp_buf, destination_buf, PIXELS);
int
test (void)
{
- BablFish *fish;
- int i;
- int OK=1;
-
+ Babl *fish;
+ int i;
+ int OK=1;
fish = babl_fish (
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"foo",
babl_model ("rgb"),
babl_type ("float"),
babl_component ("blue"),
NULL
),
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"bar",
babl_model ("ycbcr"),
babl_type ("float"),
int
test (void)
{
- BablFish *fish;
- int i;
- int OK=1;
-
+ Babl *fish;
+ int i;
+ int OK=1;
fish = babl_fish (
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"foo",
babl_model ("rgb"),
babl_type ("float"),
babl_component ("blue"),
NULL
),
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"bar",
babl_model ("ycbcr"),
babl_type ("float"),
babl_fish_process (fish, source_buf, temp_buf, PIXELS);
- fish = babl_fish ((Babl*) babl_pixel_format ("bar"),
- (Babl*) babl_pixel_format ("foo"));
+ fish = babl_fish (babl_pixel_format ("bar"),
+ babl_pixel_format ("foo"));
babl_fish_process (fish, temp_buf, destination_buf, PIXELS);
int
test (void)
{
- BablFish *fish;
- int i;
- int OK=1;
+ Babl *fish;
+ int i;
+ int OK=1;
fish = babl_fish (
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"foo",
babl_model ("grayscale"),
babl_type ("u8"),
babl_component ("luminance"),
NULL
),
- (Babl*) babl_pixel_format_new (
+ babl_pixel_format_new (
"bar",
babl_model ("grayscale"),
babl_type ("float"),